import BaseController from "../../cfw/mvc/BaseController";
import ToastModel from "./ToastModel";
import ModuleManager from "../../cfw/module/ModuleManager";
import { UIIndex } from "../../cfw/tools/Define";
import StringHelper from "../../cfw/tools/StringHelper";
import { ResultCallback } from "../../sdk/SDKConfig";
import TipModel from "./TipModel";


export default class TipController extends BaseController {

    private static ins: TipController;

    static instance() {
        if (!this.ins) {
            this.ins = new TipController()
        }
        return this.ins;
    }

    showToast(content: string, opt?) {

        let tt = window['wx'] || window['tt'];
        if (!tt) {
            if (opt) {
                content = StringHelper.replaceOpt(content, opt)
            }
            this.pushView('prefabs/ToastView', "ToastView", new ToastModel(content), ModuleManager.publicLoader(), UIIndex.TOAST)
        }
        tt.showToast({
            title: content,
            duration: 2000,
            icon: 'none',
            success(res) {
                console.log(`${res}`);
            },
            fail(res) {
                console.error(`showToast调用失败`);
            },
        });
    }


    showTip(content: string, func: ResultCallback) {
        this.pushView('prefabs/tip/TipView', "TipView", new TipModel(content, func), ModuleManager.publicLoader(), UIIndex.STACK)
    }
}
